# conding = utf-8
import time
from selenium.webdriver import ActionChains, Keys
from pages.psx.BasicData.SettlementAccount import left_menu_sales_vendor, left_menu_management_vendor, find_order_name, \
    find_order_number, find_order_phone, find_btn, find_expected_name, find_bnt_order_reset, find_no_data_yet, \
    insert_name, insert_order_close, insert_name_fail, insert_order_sure, insert_order, update_order, \
    update_order_customer, batch_checkbox, batch_operation, batch_operation_opposite_audit, batch_operation_audit, \
    batch_operation_state, batch_operation_audit_sure, default_bnt, default_status_txt, delete_order_sure_bnt, \
    delete_order_one, delete_order_two, delete_order_txt
from selenium.webdriver.common.by import By
from pages.page import Page

class SettlementAccountPage(Page):
    '''
    销售管理->销售订单操作
    '''

    def open_vendor(self):
        '''
        打开销售出库UI，如果已经打开则不会执行单击动作
        :return:
        '''
        if self.display(left_menu_sales_vendor) is False:  # 如果是隐藏状态则单击
            self.click(left_menu_management_vendor)
        self.click(left_menu_sales_vendor)

    def search_input_name(self, value):
        '''
        输入查询数据，完成查询动作
        :param value:
        :return:
        '''
        self.send_keys(find_order_name, value)

    def search_input_number(self, value):
        '''
        输入号码
        '''
        self.send_keys(find_order_number, value)

    def search_input_phone(self, value):
        '''
        输入号码
        '''
        self.send_keys(find_order_phone, value)

    def search_btn(self):
        '''
        单击查找按钮
        :return:
        '''
        self.click(find_btn)

    def search_result_text_name(self):
        '''
        单击查找完成后，获取查找结果
        :return:
        '''
        return self.text(find_expected_name)

    def search_reset(self):
        '''
        输入框查询完成后，点击重置，以便输入下一个输入框
        :return:
        '''
        self.click(find_bnt_order_reset)

    def search_no_yet_txt(self):
        '''
        获取查询输入不存在
        :return:
        '''
        return self.text(find_no_data_yet)

    def increase_table_line_num(self, insert_vendor_table_line):
        '''
        获取表格行数
        '''
        return len(self.find_elements(eval(insert_vendor_table_line)))

    def increase_bnt(self):
        '''
        单击新增按钮
        '''
        self.click(insert_order)

    def increase_name(self, value):
        '''
        输入名称
        '''
        self.send_keys(insert_name, value)

    def increase_sure(self):
        '''
        单击确定
        '''
        self.click(insert_order_sure)

    def increase_name_fail(self):
        '''
        获取新增失败文本
        '''
        return self.text(insert_name_fail)

    def increase_order_close(self):
        '''
        失败后关闭新增页面
        '''
        self.click(insert_order_close)

    def increase_name_click_back(self, value):
        '''
        单击名称输入框
        '''
        self.send_keys(insert_name, value)
        # 定义动作链
        actions = ActionChains(self.driver)
        # 删除键
        actions.send_keys(Keys.BACKSPACE)
        # 执行动作链
        actions.perform()

    def revise_order(self):
        '''
        单击编辑
        '''
        self.click(update_order)

    def revise_order_customer(self):
        '''
        获取编辑成功文本
        '''
        return self.text(update_order_customer)

    def review_checkbox(self):
        '''
        单击复选框
        '''
        self.click(batch_checkbox)

    def review_operation(self):
        '''
        悬浮单击批量操作
        '''
        self.move_element(batch_operation)

    def review_operation_opposite_audit(self):
        '''
        悬浮单击禁用
        '''
        self.move_element(batch_operation_opposite_audit)

    def review_operation_audit(self):
        '''
        悬浮单击启用
        '''
        self.move_element(batch_operation_audit)

    def review_operation_state(self):
        '''
        获取表格订单状态文本
        '''
        return self.text(batch_operation_state)

    def review_operation_audit_sure(self):
        '''
        单击禁用启用确认
        '''
        self.click(batch_operation_audit_sure)

    def defaults_bnt(self):
        '''
        单击设为默认
        '''
        self.click(default_bnt)

    def defaults_status_txt(self):
        '''
        获取默认文本
        '''
        return self.text(default_status_txt)

    def remove_order_sure_bnt(self):
        '''
        单击确认按钮
        '''
        self.move_element(delete_order_sure_bnt)

    def remove_order_one(self):
        '''
        单击删除1
        '''
        self.click(delete_order_one)

    def remove_order_two(self):
        '''
        单击删除2
        '''
        self.click(delete_order_two)

    def remove_order_sure_bnt(self):
        '''
        单击确认按钮
        '''
        self.move_element(delete_order_sure_bnt)

    def remove_order_txt(self):
        '''
        获取删除失败文本
        '''
        return self.text(delete_order_txt)

    def remove_table_line_one(self, delete_order_txt):
        '''
        获取删除后表格行数
        '''
        return len(self.find_elements(eval(delete_order_txt)))




